
 ALTER        proc sp_update_inventory_lot (
 
 @date_in varchar (20),
 @qty_in varchar (20),
 @lot_id varchar (20),
 @lot_no varchar (20),
 @test_qty int,
 @rejected_qty int
 )
 
 
 as
 begin
 select * from lot_table
 	if @date_in = '01/01/1900' 
 	begin
 		set @date_in = null
 	end
 
 	declare @temp_lot_no varchar(20)
	declare @temp_bal_qty varchar(20)
	declare @old_qty_In varchar(20)

 	select @temp_lot_no= Lot_Number from Lot_Table where Lot_ID = @lot_id
 	if @temp_lot_no <> @lot_no
 	begin
 		update Lot_Table set Lot_Number = @lot_no where Lot_ID = @lot_id 
 	end
 	select @temp_bal_qty = IL_Qty_Balance, @old_qty_In = IL_Qty_In from Inventory_Lot where Lot_Id = @lot_id
	if @temp_bal_qty = null
	begin
	 	update inventory_lot set IL_Date_In = @date_in, IL_Qty_In = @qty_In, IL_Test_Qty = @test_qty, IL_Rejected_Qty = @rejected_qty where Lot_ID = @lot_id
	end
	else
	begin
		update inventory_lot set IL_Qty_Balance = ( (convert(int , @qty_In)-convert(int, @old_qty_In))+convert(int, @temp_bal_qty) ), IL_Date_In = @date_in, IL_Qty_In = @qty_In, IL_Test_Qty = @test_qty, IL_Rejected_Qty = @rejected_qty where Lot_ID = @lot_id
	end
 
 end

